package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.common.entity.PageDTO;
import com.boss.common.util.PageUtils;
import com.boss.framework.dto.PaginationDTO;
import com.boss.salary.entity.SalaryGrantSign;
import com.boss.salary.service.ISalaryGrantSignService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.http.MediaType;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/salaryGrantSignController", produces = MediaType.APPLICATION_JSON_VALUE)
public class SalaryGrantSignController extends BasicinfoBaseController {

    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(SalaryGrantSignController.class);

    @Autowired
    private ISalaryGrantSignService iSalaryGrantSignService;

    /**
     * 分页查询工资发放签报
     *
     * @return
     */
    @GetMapping("/getSalaryGrantSign")
    public ApiResultDTO getSalaryGrantSign(@RequestHeader("X-Token") String tokenid,
                                           @RequestParam(value = "page") String page,
                                           @RequestParam(value = "limit") String limit,
                                           @RequestParam(value = "bddw", required = false) String bddw,
                                           @RequestParam(value = "gzlx", required = false) String gzlx,
                                           @RequestParam(value = "salaCardBanks", required = false) String salaCardBanks) {
        try {
            String province = getUser(tokenid).getProvince();
            Map<String, Object> queryParam = new HashMap<>();
            queryParam.put("province",province);
            queryParam.put("bddw", bddw);
            queryParam.put("gzlx", gzlx);
            queryParam.put("salaCardBank", salaCardBanks);
            PaginationDTO paginationDTO = PageUtils.buildPaginationDTOPage(page, limit);
            PageDTO<SalaryGrantSign> pageDTO = iSalaryGrantSignService.getSalaryGrantSignPage(paginationDTO, queryParam);
            return ApiResultDTO.success(pageDTO, null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "获取数据异常");
        }
    }
}
